import requests

url = 'https://www.baidu.com'

# 不携带headers请求百度
response1 = requests.get(url)

print(len(response1.content.decode()))  # 2349

# 携带headers参数请求百度
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36'
}

# 加上请求头才可以获取到response中的所有内容
response2 = requests.get(url, headers=headers)

response2.encoding = 'utf-8'

print(len(response2.text))  # 303090
print(response2.text)



